package com.kinyx.framework.utils;

import static org.junit.Assert.assertThrows;

import org.junit.Assert;
import org.junit.Test;

import com.kinyx.framework.enums.impl.ErrorCode0;
import com.kinyx.framework.exception.KRuntimeException;

public class KArrayUtils_Tester_subArray {

	@Test
	public void test() {
		final byte[] arr = new byte[]{
				1, 2, 3
		};
		assertThrows(KRuntimeException.class, () -> {
			try {
				KArrayUtils.toString(KArrayUtils.subArray(arr, 2, 1));
			} catch (final KRuntimeException e) {
				Assert.assertEquals(ErrorCode0.StartIndexMoreThenEndIndex, e.getErrorCode());
				throw e;
			}
		});
		assertThrows(KRuntimeException.class, () -> {
			try {
				KArrayUtils.toString(KArrayUtils.subArray(arr, -1, 0));
			} catch (final KRuntimeException e) {
				Assert.assertEquals(ErrorCode0.StartIndexLessThenMinIndex, e.getErrorCode());
				throw e;
			}
		});
		Assert.assertEquals("[1]", KArrayUtils.toString(KArrayUtils.subArray(arr, 0, 1)));
		Assert.assertEquals("[1, 2]", KArrayUtils.toString(KArrayUtils.subArray(arr, 0, 2)));
		Assert.assertEquals("[1, 2, 3]", KArrayUtils.toString(KArrayUtils.subArray(arr, 0, 3)));
		assertThrows(KRuntimeException.class, () -> {
			try {
				KArrayUtils.toString(KArrayUtils.subArray(arr, 0, 4));
			} catch (final KRuntimeException e) {
				Assert.assertEquals(ErrorCode0.EndIndexMoreThenMaxIndex, e.getErrorCode());
				throw e;
			}
		});
	}

}
